$(document).ready(function () {

    // 返回顶部

    $('#back_top').click(function () {

        $('html,body').animate({scrollTop: 0}, 1000);

    })


    // 导航栏

    $('nav').children('div').children('ul').children('li').mouseenter(function () {

        $('nav').children('div').children('ul').children('li').removeClass('nav_choose')

        $(this).addClass('nav_choose')

    })

    $('nav').mouseleave(function () {

        $('nav').children('div').children('ul').children('li').removeClass('nav_choose')

        $('#sy').addClass('nav_choose')

    })


    // 导航栏下拉菜单

    $('nav .nav_down').mouseenter(function () {

        $(this).find('.nav_down_list').stop(true, true).slideDown()

        $(this).children('img').attr('src', 'img/nav_down2.png')

    })

    $('nav .nav_down').mouseleave(function () {

        $(this).find('.nav_down_list').stop().slideUp('fast')

        $(this).children('img').attr('src', 'img/nav_down.png')

    })


    // 侧边导航
    $('#banner .slide_nav ul li').hover(function () {

        $(this).find('img').attr('src', 'img/' + $(this).attr('id') + '.png')

        $('#banner .slide_nav_right').fadeIn()

        $(this).addClass('one_choice')

            .siblings().removeClass('one_choice')

        // console.log($(this).attr('id'))

        $('#banner .slide_nav_right')
            .find('.' + $(this).attr('id'))
            .stop(true)

            .fadeIn(17)


            .siblings()

            .hide()

    }, function () {
        $(this).find('img').attr('src', 'img/a' + $(this).attr('id') + '.png')

    })


    // 鼠标离开整体区域时，右半部分消失，做半部分恢复样式

    $('#banner .slide_nav').mouseleave(function () {

        $('#banner .slide_nav_right').fadeOut()

        $('#banner .slide_nav ul li').removeClass('one_choice')

    })

    // 轮播图
    function addClass(addr) {

        $('.open .bottom ul li')

            .find(addr)

            .parent()

            .siblings()

            .find('span')

            .removeClass('xuanzhong')

            .end().end().end()

            .siblings()

            .addClass('xuanzhong')

    }

    function clearfont(addr) {

        $('.open .bottom ul li')

            .find(addr)

            .parent()

            .siblings()

            .find('div')

            .addClass('clearfont')

            .removeClass('xuanzhong')

    }

    function toogle(addr) {

        $(addr).parent().parent()

            .show()

            .siblings()

            .hide()

    }

    // 视频列表切换

    $('.konwus .v_right ul li')

        .click(function () {

            $('.konwus')

                .find('.v_wrap .v_left')

                .html($(this).find('.embed').html())

            $(this).addClass('choiced')

                .siblings().removeClass('choiced')

        })


    // 从json文件读取就业信息

    $.getJSON('json/jy.json', null, function (info, infoindex) {

        for (var i in info.name) {

            $('<tr id=' + i + '></tr>').appendTo('#xb_t2')

            $('<td></td>').text(info.name[i]).appendTo('#' + i)

        }

        for (var i in info.company) {

            $('<td></td>').text(info.company[i]).appendTo('#' + i)

        }

        for (var i in info.yx) {

            $('<td></td>').text(info.yx[i]).appendTo('#' + i)

        }

        for (var i in info.zy) {

            $('<td></td>').text(info.zy[i]).appendTo('#' + i)

        }


        // 就业喜报滚动

        $("#xb_t2").rollGallery({

            direction: "top",

            speed: 1000,

            showNum: 14

        })

    })


    // 报名

    $("#iform .button").click(function (ev) {

        ev.preventDefault()


        var input1 = $('#iform .form-control:eq(0)').val();

        var input2 = $('#iform .form-control:eq(1)').val();

        var input3 = $('#iform .form-control:eq(2)').val();

        var reg2 = /^1[3578]\d{9}$/;

        var reg3 = /^[1-9]\d{4,10}$/;


        if (input1 == "") {

            alert("姓名不能为空");

        } else if (!reg2.test(input2)) {

            alert("手机格式不符！！请重新填写！")

        } else if (!reg3.test(input3)) {

            alert("QQ格式不符！！请重新填写！");

        } else {

            $("#iform").submit();

        }


    })


    $(window).scroll(function () {

        if ($(this).scrollTop() > 171) {

            $("#hhService").height(260)

                .find('.back_top').css('display', 'block')

            $('nav').css({

                'position': 'fixed',

                'top': '0',

                'left': '0',

                'z-index': '999999',

                'border-bottom': '1px solid #e6e6e6'

            })

            $('body').css({

                'padding-top': '90px'

            })

        } else {

            $("#hhService").height(208)

                .find('.back_top').css('display', 'none')

            $('nav').css({

                'position': 'initial',

                'top': '0',

                'left': '0',

                'border-bottom': 'none'

            })

            $('body').css({

                'padding-top': '0'

            })

        }

    })


    // 底部固定报名框

    $("#fixform .button").click(function (ev) {

        ev.preventDefault()


        var input1 = $('#fixform .form-control:eq(0)').val();

        var input2 = $('#fixform .form-control:eq(1)').val();

        var input3 = $('#fixform .form-control:eq(2)').val();

        var reg2 = /^1[3578]\d{9}$/;

        // var reg3 = /^[1-9]\d{4,10}$/;


        if (input1 == "") {

            alert("姓名不能为空~");

        } else if (!reg2.test(input2)) {

            alert("手机格式不符！！请重新填写！")

        } else {

            $("#fixform").submit();

        }

    })

});


// hot_info

$(window).load(function () {

    $("#pic_list_1").cxScroll({

        direction: "bottom",

        speed: 1200,

        time: 2100,

        plus: false,

        step: 1,

        minus: false

    });


});

//s_slide global config

function slideConfig(param) {

    $(param[0]).slide({

        titCell: param[7],

        mainCell: param[1],

        autoPage: true,

        effect: 'leftLoop',

        autoPlay: true,

        scroll: param[2],

        vis: param[3],

        easing: 'swing',

        delayTime: param[4],

        interTime: param[5],

        pnLoop: true,

        trigger: 'mouseover',

        mouseOverStop: param[6]

    });

}

// banner
$('.banner_pic_scroll').slide({
    titCell: '.hd ul',
    mainCell: '.bd ul',
    autoPage: true,
    effect: 'fade',
    autoPlay: true,
    scroll: 1,
    vis: 1,
    easing: 'linear',
    delayTime: 700,
    interTime: 3000,
    pnLoop: true,
    trigger: 'mouseover',
    mouseOverStop: true
});

//employ

slideConfig([".emp_pic_scroll", ".bd ul", 1, 4, 500, 2500, true, ''])

//teacher

slideConfig([".teac_pic_scroll", ".bd ul", 1, 4, 500, 3500, true, ''])

//product

slideConfig([".pro_pic_scroll", ".bd ul", 1, 1, 800, 4000, true, ''])

//environ

slideConfig([".envi_pic_scroll", ".bd ul", 1, 5, 600, 2500, false, '.hd ul.hide_bar'])

env_star()

var env_s = setInterval(env_star, 2500)

//coll_frim

$(".firm_pic_scroll").slide({

    titCell: "",

    mainCell: ".bd ul",

    autoPage: true,

    effect: "leftMarquee",

    autoPlay: true,

    scroll: 1,

    vis: 5,

    easing: 'swing',

    interTime: 20,

    pnLoop: true,

    trigger: 'mouseover',

    mouseOverStop: true

});

//custom scroll

var custom_scroll = new scrollbot(".v_right", 13).setStyle({

    "background": "#ffffff",

    "opacity": "0.85",

    "z-index": "2",

    "top": "5px",

    "border-radius": "50%",

    "height": "13px"

}, {

    "background": "rgba(0,0,0,0)"

});

var psuedo = document.createElement("div");

psuedo.style.cssText = "height:100%;width:1px;left:6px;background:#ffffff;opacity:0.4;position:absolute;z-index:1";

custom_scroll.scrollBarHolder.appendChild(psuedo);

document.onreadystatechange = function () {

    custom_scroll.refresh();

}

//课程中心效果

jQuery(document).ready(function () {

    jQuery(".course_core_wrap>ul>li").bind("mouseenter mouseleave", function (e) {

        var _this = jQuery(this)

        var w = _this.width();

        var h = _this.height();

        var x = (e.pageX - _this.offset().left - (w / 2)) * (w > h ? (h / w) : 1);

        var y = (e.pageY - _this.offset().top - (h / 2)) * (h > w ? (w / h) : 1);

        var direction = Math.round((((Math.atan2(y, x) * (180 / Math.PI)) + 180) / 90) + 3) % 4; //direction的值为“0,1,2,3”分别对应着“上，右，下，左”

        var eventType = e.type;

        var mask = _this.children('.course_mask');

        // 228 220

        if (e.type == 'mouseenter') {

            switch (direction) {

                case 0:

                    mask.css({

                        top: -200,

                        left: 0

                    });

                    break;

                case 1:

                    mask.css({

                        top: 0,

                        left: 228

                    });

                    break;

                case 2:

                    mask.css({

                        top: 200,

                        left: 0

                    });

                    break;

                case 3:

                    mask.css({

                        top: 0,

                        left: -228

                    });

                    break;

            }

            mask.stop(true).animate({

                left: 0,

                top: 0

            }, 200);

        } else {

            var end = {};

            switch (direction) {

                case 0:

                    end = {

                        top: -200,

                        left: 0

                    };

                    break;

                case 1:

                    end = {

                        top: 0,

                        left: 228

                    };

                    break;

                case 2:

                    end = {

                        top: 200,

                        left: 0

                    };

                    break;

                case 3:

                    end = {

                        top: 0,

                        left: -228

                    };

                    break;

            }

            mask.stop(true).animate(end, 200);

        }

    });

});

(function (e) {

    e.fn.fix = function (t) {

        var n = {

                "float": "right",

                durationTime: 100

            },

            t = e.extend(n, t);

        this.each(function () {

            var n = e(this),

                a = n.offset().top;

            n.css(t.float, 0),

                e(window).bind("scroll",

                    function () {

                        var r = a + e(window).scrollTop() + "px";

                        n.animate({

                                top: r

                            },

                            {

                                duration: t.durationTime,

                                queue: !1

                            })

                    })

        })

    }

})(jQuery)

$(function () {
    $("#hhService").fix()
});

$(".layer").click(function () {
    // window.location.href = "http://www.zhiyou100.com/software";
    window.open("http://www.zhiyou100.com/works")
    // window.location.target="_blank"
    // $(this).attr("target",_blank)
})

function env_star() {

    // 教学环境状态跟随

    var $_hide_bar = $('.environ .hide_bar li')

    var $_s_bar = $('.environ .s_bar li')

    $_s_bar.hover(function () {

        $(this).addClass('on_cho').siblings().removeClass('on_cho')

        $_hide_bar.eq($(this).data('num')).mouseenter()

    })

    function choi_bar(i) {

        $_s_bar.eq(i).addClass('on_cho').siblings().removeClass('on_cho')

    }

    function is_s(num, index) {

        if ($_hide_bar.eq(j).hasClass('on') && $_hide_bar.eq(j).text() == num) {

            choi_bar(index)

        }

    }

    for (var j = 0; j < $_hide_bar.length; j++) {

        is_s(1, 0)

        is_s(9, 1)

        is_s(14, 2)

        is_s(20, 3)

        is_s(25, 4)

        is_s(28, 5)

    }

}

$('#ad_vdo').on({
    contextmenu: function () {
        $(this).get(0).pause();
        return false;
    },
    click: function () {
        $(this).get(0).play()
    },
})

$(document).ready(function () {
    var $_zFvc = $('#voucherForm')
    $_zFvc.bootstrapValidator()
    $('#voucherSubmit').click(function (e) {
        e.preventDefault();
        $_zFvc.submit()
        var data = $_zFvc.serializeArray()
        if (data[0].value && data[1].value) {
            $.ajax({
                url: 'http://www.zhiyou100.com:3000/leavaWord',
                data: data,
                method: 'POST',
                dataType: 'json'
            }).done(function (res) {
                if (res.status == 'success') {
                    alert(res.message)
                    $_zFvc.get(0).reset()
                    $('.voucher_mask').slideToggle()
                } else {
                    alert(res.message)
                }
            })
                .fail(function (err) {
                    alert(err.statusText)
                })
        }
    })
});
$(document).ready(function () {
    var $_zF = $('#zyForm')
    $_zF.bootstrapValidator()
    $('#submit').click(function (e) {
        e.preventDefault();
        $_zF.submit()
        var data = $_zF.serializeArray()
        if (data[0].value && data[1].value) {
            $.ajax({
                url: 'http://www.zhiyou100.com:3000/leavaWord',
                data: data,
                method: 'POST',
                dataType: 'json'
            }).done(function (res) {
                if (res.status == 'success') {
                    alert(res.message)
                    $_zF.get(0).reset()
                    $('html,body').animate({scrollTop: 0}, 'slow');
                } else {
                    alert(res.message)
                }
            })
                .fail(function (err) {
                    alert(err.statusText)
                })
        }
    })
});
